package com.lmx.healthcode.util;

import android.content.Context;
import android.view.View;
import android.view.inputmethod.InputMethodManager;

import com.lmx.healthcode.base.MyApp;

/**
 * @author Leung
 * @date 2020/9/12 20:53
 */
public class KeyboardUtil {

    public static void openKeyboard(View view) {
        InputMethodManager imm = (InputMethodManager) MyApp.getInstance()
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        if (imm != null) {
            view.requestFocus();
            imm.showSoftInput(view, 0);
        }
    }

    public static void closeKeyboard(View view) {
        InputMethodManager imm = (InputMethodManager) MyApp.getInstance()
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        if (imm != null) {
            view.clearFocus();
            imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
        }
    }

}
